package com.faker.dba.controller;

import com.faker.dba.model.dto.LoginDto;
import com.faker.dba.service.UserCenterService;
import com.faker.dba.wrapper.AesWrapMapper;
import com.faker.dba.wrapper.Wrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Api("用户中心控制层")
@Slf4j
@Controller
@RequestMapping(value = "userCenter")
public class UserCenterController extends BaseController {


    /**
     * 用户中心服务层
     */
    @Autowired
    private UserCenterService userCenterService;

    @ResponseBody
    @ApiOperation("登录方法")
    @PostMapping(value = "/login")
    public Wrapper login(@RequestBody LoginDto params) {
        log.info(super.postMethodLog());
        log.info(params.toString());
        try {
            return userCenterService.login(params);
        } catch (Exception e) {
            log.error(super.getApiOperationTitle() + "错误", e);
            return AesWrapMapper.error(super.getApiOperationTitle() + "错误：" + e.getMessage());
        }
    }
}
